Aldo Hoeben
www.fieldOfView.nl
www.studioPKO.nl
This tutorial shows techniques for including video in Shockwave 3D scenes. This tutorial starts with an introduction that shows what's so cool about the addition of video to Macromedia Shockwave 3D. I will show you a compelling demo of a video feed used in an interactive panorama.
While using (streaming) video was possible before Macromedia Director MX using a Real Media or QuickTime member, this meant that your audience had to install yet another large plug-in to experience your work. Other solutions required third-party Xtra extensions and were often not cross platform or didn't work online. Since Director MX, you can use Macromedia Flash MX Video, which does not have these problems. In Macromedia Director MX 2004, you can now use Flash Components to make life easier. In the tutorial, you will use a Flash Component to show the streaming video. The techniques to use the video in a 3D scene also apply to many other media types.
Requirements
To complete this tutorial you will need to install the following software and files:
Director MX 2004
Macromedia Flash MX 2004
Tutorials and sample files:
Windows lecture-tv.zip (424 KB)
Macintosh lecture-tv.sit (435 KB)
Introduction: Video in 3D
Before showing you how to use video in Shockwave 3D, I first want to discuss why you would want to include streaming video in Shockwave 3D at all. You could argue that in real-time Shockwave 3D, there is little room for video; You either choose prerendered Shockwave 3D graphics (such as movies, like Toy Story), or you use real-time rendered geometry (such as Shockwave 3D, VRML, and so forth). In games, you often see animated textures on real-time geometry—for example, an animated terminal on a desk in an office environment. But this hardly justifies the use of streaming video. Even though a television screen with an actual television show on it may seem like a "neat trick," the effect soon wears off.
Having said all this, let's have a look at the demo. Please note that since it includes a streaming video, you need a decent internet connection (256 Kbit or faster recommended).
Open the demo in a pop-up window.
If all went well, you saw a lecture about Rich Internet Applications by Al Ramadan, Executive Vice President of Marketing for Macromedia. You may have noticed, however, that after Al appears on stage, the camera pans a little and the mouse cursor changes into a cross hair. You can now interactively navigate the scene by clicking the Shockwave scene and dragging in the direction you want to view. You can look up at the slides for Al's presentation or you can look around to see the lecture room and the audience.
Note that you can find the original presentation that includes the video stream here.
How It's Done: The Panorama
The type of scene you viewed is commonly referred to as a panorama. You may know them as QuickTime VR or another brand name. It would take too long to explain all the details of panoramas, but if you want to know more about panoramas and how to make them, this site is a nice starting point.
Figure 1. The cubic panorama
The lecture demo includes a cubic panorama. The scene is wrapped in a cube and a camera is placed inside the cube. By clicking and dragging the movie, you rotate the camera to reveal other areas of the inside of the cube (see the "outside view" above). Other panorama viewer use the same method; however, using Shockwave 3D has one great advantage: While most other viewers render the panorama using software, Shockwave 3D gives you hardware acceleration. This provides ultra-smooth display and navigation, comparable almost to the smooth graphics you see in modern games.
With the graphics card handling most of the panorama display, Director has time to spare to add more to the panorama, such as our Al "avatar." To add Al to the panoramic scene, place a texture with his image on a piece of "cardboard" geometry (a plane) that you place inside the panorama cube. As the camera rotates, the piece of cardboard pans in and out of view along with the rest of the panorama and since you don't see the edges of the plane, it looks as if Al is really in the scene.
Macromedia Flash MX 2004 Video in Shockwave 3D
Now that you know why and how you'd want to use Macromedia Flash video in a Shockwave 3D scene, you'll learn how to do it. First, you must get the video into Director. In Director MX, you could import a Flash MX movie and set that up to play the video. It would involve building a movie in Flash MX, adding a Video Clip to it, and using some ActionScript to play the streaming video.
In Director MX 2004, you can use Macromedia Flash Components. Flash Components are a bit like the standard behaviors in the Library. You do not have to know exactly how they work to use them, and with a few simple clicks they can do complex stuff for you. I went ahead and created a Flash Component for you that plays a video stream off a Flash Communication server. If you would like to create your own components, check out Macromedia Flash Developer Center.
If you haven't done so already, download the sample files at the beginning of the article. In the sample files, you will find some completed source files, along with a Macromedia Flash Component named FlashCom_StreamPlayer.swc. Place this component in the Director MX 2004/Configuration/Components folder. The next time you start Director MX 2004, it will be available in the Library palette as shown in Figure 2 below.
Figure 2. The FlashCom_StreamPlayer component
You can now drag the FlashCom_StreamPlayer component from the library to the cast or directly to the stage to make a sprite. In the Property inspector, specify the following settings (you can leave the other settings with their default values):
| autoPlay | autoPlay true |
|---|---|
| streamLocation | rtmp://216.104.212.40/experiencematters |
| streamName | riaseminar_high |
The streamLocation and streamName specify where to find the particular Macromedia Flash Communication Server and video stream. The autoPlay property specifies if the stream is automatically opened, or if it should wait for a command that you will send to it.
Rewind and play your movie. Provided that your Internet connection works properly, you will see Al appear on stage and start his lecture, though his image is distorted. The video stream you are going to use is 300 by 300 pixels, but you are playing it back in a 320 by 240 sprite. Since you are going to use the video as a texture for a Shockwave 3D model, it's best to use dimensions that are powers of two. Resize the sprite to 256 by 256 pixels; this will scale the video stream down a bit, but these dimensions give a good quality/performance ratio. Remember that all textures you use in your scene should fit into the video memory at once. Now Al's image displays correctly.
Note that if you are not using Director MX 2004 yet, you can use a Flash member and set up the streaming video yourself, or, you can even use a QuickTime or AVI video if you like. If you do, remember to set the member's Director to Stage value to false.
Next you use the image of this movie for a texture in a 3D scene. If you've read a tutorial on using Real Media in 3D before, you may expect this to be as simple as making a texture with the Macromedia Flash component member as source, and updating the texture. Unfortunately, this won’t work for much more than Real video members. There is another approach though that will work with a wide range of media, and it will even have a bit better performance than using the Real video method above.
Since you can make the video appear on Stage, grab that part of the Stage and use it for your texture. Be sure to set the directToStage property of the Macromedia Flash component to false. This approach may sound less elegant, but it works surprisingly well. It works for the Flash Component, as well as for regular Flash files, QuickTime files, AVI files, and so forth as long as the content can be rendered non-Direct-to-Stage. Unfortunately, this rules out the newly added Windows Media and DVD video added to Director MX 2004. Well, you can't have it all. Yet...
Even though this approach works, it's a bit odd to see the 3D scene with the video in it, and your original video sprite at the same time. Now you will hide the video sprite. There are two methods for doing this, one works for Director authoring and projectors; the othermethod works in the browser.
In authoring and in a projector, you can use a Movie in a Window (MIAW) to play the video and grab an image from it. You will create the movie and play your video stream, but don't open the window itself. The window will stay invisible, but the stream will play and you can grab an image from it!
Here is the theory on grabbing the appropriate part of the stage for your texture in practice. Create two movies. One of these movies will be your invisible MIAW. Make this movie 256 by 256 pixels and add the streaming video to it. In the other movie, create or import a 3D member and add the following behavior to it:
property pWorld
property pTexture, pImage
property pVideoWindow
on beginSprite me
pWorld = sprite(me.spriteNum).member
-- create new 256*256 texture from an image object
pImage = image(256,256,32)
pTexture = pWorld.newTexture("Streaming Texture", \ #fromImageObject,pImage)
-- use out texture for the screen
-- in this example, SCREEN IMAGE is already applied to our object
tShader = pWorld.shader("SCREEN IMAGE")
tShader.texture = pTexture
-- open a MIAW containing our video SWC, but DON'T open() it!
-- the video will run anyway, but we wont see it
pVideoWindow = window().new("video")
pVideoWindow.fileName = "MIAW.dir"
end beginSprite
on endSprite me
-- remove the window and the texture we created
pVideoWindow.forget()
pWorld.deleteTexture("Streaming Texture")
end endSprite
on prepareFrame me
-- eventhough our window is not visible, we can still grab its image
pImage.copyPixels((the stage).image,pImage.rect, pFlashSprite.rect)
pTexture.image = pImage
end prepareFrame
In Shockwave, you cannot use Movies in a Window (MIAW), but you can hide the video sprite through another trick. Expand the size of the stage to include the Macromedia Flash sprite, but simply crop out the sprite in the Shockwave window. Say you have a 600 by 400 pixel 3D sprite on the stage, and you want to use your 256 by 256 texture. To do so, increase the stage size to 856 by 400 pixels and place the Fash sprite in the added space. In the Publish Settings, set the General Setting to "Pixel Dimensions" at 600 by 400. In the Shockwave tab, set the Stretch Style to "No Stretching". This will crop the Flash sprite in the browser, but still lets the user grab the part of the stage the Flash sprite is on.
property pWorld
property pTexture, pImage
property pVideoSprite
on beginSprite me
pWorld = sprite(me.spriteNum).member
-- create new 256*256 texture from an image object
pImage = image(256,256,32)
pTexture = pWorld.newTexture("Streaming Texture", \ #fromImageObject,pImage)
-- use out texture for the screen
-- in this example, SCREEN IMAGE is already applied to our object
tShader = pWorld.shader("SCREEN IMAGE")
tShader.texture = pTexture
-- the sprite of our flash member
pVideoSprite = sprite(2)
end beginSprite
on endSprite me
-- remove the texture we created
pWorld.deleteTexture("Streaming Texture")
end endSprite
on prepareFrame me
pImage.copyPixels((the stage).image,pImage.rect, pVideoSprite.rect)
pTexture.image = pImage
end prepareFrame
Source Files
You can download a complete version of the project using the sample files link at the beginning of the article. The sample files include the Flash Component that facilitates showing streaming flash video. Feel free to use it in this tutorial and in other projects. If you are not using Director MX 2004, you can not use the Flash Component. You can use any Flash file instead, or even a QuickTime video, just be sure to set the member's Direct-to-Stage property to false.
Using the techniques in this tutorial, you can now integrate Macromedia Flash video streams in your work without depending on your audience to install Shockwave and another large plug-ins, such as Real or QuickTime. Don't limit using the techniques for video in Shockwave 3D though. You can use the same techniques to apply any Flash movie as a texture in your movie with all the unique features of Flash MX 2004—scripted vector-animations, perfectly anti-aliased text, and even your local webcam view, you name it!
Aldo Hoeben works as an independent interaction designer at his company studioPKO, based in the Netherlands. Recently Aldo decided to emphasize his panoramic imaging products and started promoting his brand fieldOfView.
Apart from his work as a designer, Aldo works as a part-time assistant professor at the ID-Studiolab within the Delft University of Technology. In his research he uses quick prototypes made with Macromedia Director to evaluate interaction concepts. He is also involved in teaching students how to use Macromedia Director for making product presentations and interaction prototypes.
Aldo thinks that speaking about himself in third person is silly